package cn.ltpcloud.common.config;

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 接口文档配置类
 *
 * @author jiejiebiezheyang
 * @since 2024-03-01 10:00
 */
@Configuration
public class OpenAPIConfig {


    @Bean
    public OpenAPI openAPI() {
        return new OpenAPI().info(
                        new Info()
                                .title("spring-boot-3-quickly-start")
                                .description("springboot3项目快速启动")
                                .contact(new Contact()
                                        .name("Byte Pulse")
                                        .email("1964234252@qq.com")
                                        .url("https://gitee.com/jiejiebiezheyang/spring-boot-3-quickly-start"))
                                .version("1.0.0")
                ).components(components())
                .addSecurityItem(new SecurityRequirement().addList("Authorization"));
    }

    private Components components() {
        return new Components()
                .addSecuritySchemes("Authorization",
                        new SecurityScheme().type(SecurityScheme.Type.APIKEY).in(SecurityScheme.In.HEADER).name("Authorization"));
    }

}